import { createStore } from 'vuex'

const admin: IAdmin = {
  t_admin_pk: 0,
  admin_name: '',
  token: '',
  mobile: '',
  funList: [],
  funSet: [],
  pageURLs: []
}



export default createStore({
  state: {
    admin,
    list: [
      { name: "红红", sex: "女", age: 18, id: 1 },
      { name: "莲莲", sex: "女", age: 19, id: 5 },
      { name: "爱爱", sex: "女", age: 16, id: 2 },
      { name: "小文", sex: "男", age: 16, id: 3 },
      { name: "小强", sex: "男", age: 18, id: 4 },
    ]
  },
  getters: {
    girlList(state) {
      return state.list.filter(v => v.sex == "女");
    },
    // 成年女生
    // getters第二个参数，可以访问其它getters
    adultGirlList(state,getters) {
      return getters.girlList.filter((v:any) => v.age >= 18);
    },
    // 返回指定年龄的列表
    // getters高级用法：可以返回一个函数
    getListAsAge: state => (age:number) => state.list.filter(v => v.age == age),
    boyList(state) {
      return state.list.filter(v => v.sex == "男");
    }
  },
  mutations: {
    // mutations里面的方法只能是同步方法，可以使用async
    addStu(state,payload) {
      state.list.push(payload);
    }
  },
  // actions里面的方法可以进行异步操作
  actions: {
    // 参数一：上下文对象：context.commit(),context.dispatch(),context.state,context.getters
    addStu(context,payload) {
      context.commit("addStu",payload)
    }
  },
  modules: {
    
  }
})
